package com.imooc.mybatisplusappdemo.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import java.util.HashMap;
import java.util.Map;

/**
 * @author caiqian
 * @date 2021/3/24 11:12
 */
public class ResultUtil {

  /**
   * 构建分页查询的返回结果
   * @param page
   * @return
   */
  public static R<Map<String,Object>> buildPageR(IPage<?> page){
    HashMap<String, Object> map = new HashMap<>();
    map.put("count",page.getTotal());
    map.put("records",page.getRecords());

    return R.ok(map);
  }

  public static R<Object> buildR(boolean success){
    if (success){
      return R.ok(null);
    }

    return R.failed("新增出错!");
  }

}
